home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3 / CHAPTE11 / GETSTATS / PHONE.C < prev    next >
C/C++ Source or Header  |  1996-04-28  |  23KB  |  649 lines

  1. #include <windows.h> 
  2. #include <windowsx.h> 
  3. #include "phone.h" 
  4. #include "tapi.h"
  5.  
  6. #define BUFSIZE 256
  7. #define APIHIVERSION     0x00010028    /* 1.40 */
  8. #define APILOWVERSION    0x00010000    /* 1.0 */
  9. #define EXTHIVERSION     0x00010005    /* 1.5 */
  10. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  11. #define MAX_PHONE        2
  12. #define OWNER            0
  13. #define MONITOR        1
  14.  
  15. LPCTSTR lpszAppName = "phoneGetStatus";
  16. LPCTSTR lpszTitle   = "phoneGetStatus"; 
  17.  
  18.  
  19. #if defined (WIN32)
  20.     #define IS_WIN32 TRUE
  21. #else
  22.     #define IS_WIN32 FALSE
  23. #endif
  24.  
  25. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  26. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  27. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  28.  
  29. HINSTANCE hInst;   // current instance
  30. HWND hWnd;         // parent window handle
  31. HWND hListWnd;     // listbox
  32. HDC  hdc;
  33. TEXTMETRIC  tm ;
  34.  
  35. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  36.  
  37.  
  38. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  39.                       LPTSTR lpCmdLine, int nCmdShow)
  40. {
  41.    MSG      msg;
  42.    WNDCLASS wc;
  43.  
  44.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  45.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  46.    wc.cbClsExtra    = 0;                      
  47.    wc.cbWndExtra    = 0;                      
  48.    wc.hInstance     = hInstance;              
  49.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  50.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  51.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  52.    wc.lpszMenuName  = lpszAppName;              
  53.    wc.lpszClassName = lpszAppName;              
  54.  
  55.    if ( IS_WIN95 )
  56.    {
  57.       if ( !RegisterWin95( &wc ) )
  58.          return( FALSE );
  59.    }
  60.    else if ( !RegisterClass( &wc ) )
  61.       return( FALSE );
  62.  
  63.    hInst = hInstance; 
  64.  
  65.    hWnd = CreateWindow( lpszAppName, 
  66.                         lpszTitle,    
  67.                         WS_OVERLAPPEDWINDOW, 
  68.                         CW_USEDEFAULT, 0, 
  69.                         CW_USEDEFAULT, 0,  
  70.                         NULL,              
  71.                         NULL,              
  72.                         hInstance,         
  73.                         NULL               
  74.                       );
  75.  
  76.    if ( !hWnd ) 
  77.       return( FALSE );
  78.  
  79.    ShowWindow( hWnd, nCmdShow ); 
  80.    UpdateWindow( hWnd );         
  81.  
  82.    while( GetMessage( &msg, NULL, 0, 0) )   
  83.    {
  84.       TranslateMessage( &msg ); 
  85.       DispatchMessage( &msg );  
  86.    }
  87.  
  88.    return( msg.wParam ); 
  89. }
  90.  
  91.  
  92. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  93. {
  94.     WNDCLASSEX wcex;
  95.  
  96.    wcex.style         = lpwc->style;
  97.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  98.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  99.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  100.    wcex.hInstance     = lpwc->hInstance;
  101.    wcex.hIcon         = lpwc->hIcon;
  102.    wcex.hCursor       = lpwc->hCursor;
  103.    wcex.hbrBackground = lpwc->hbrBackground;
  104.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  105.    wcex.lpszClassName = lpwc->lpszClassName;
  106.  
  107.    // Added elements for Windows 95.
  108.    //...............................
  109.    wcex.cbSize = sizeof(WNDCLASSEX);
  110.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  111.                             IMAGE_ICON, 16, 16,
  112.                             LR_DEFAULTCOLOR );
  113.             
  114.    return RegisterClassEx( &wcex );
  115. }
  116.  
  117. typedef struct tagMYINFO    // general application information
  118. {
  119.    HPHONEAPP phoneApp;      // instance handle TAPI gives back to us                                                                              through phoneInitialize()
  120.    DWORD dwNumDevices;     // number of available devices
  121.    DWORD dwAPIVersion;     // API version the phone supports
  122.     DWORD dwExtVersion;        // extended version
  123. } MYINFO;
  124.  
  125. typedef struct tagPHONEINFO  // information on an open phone
  126. {
  127.    HPHONE     hPhone;           // handle to the phone as returned by phoneOpen 
  128.     DWORD      dwDeviceID;            // device ID of the phone device
  129.     DWORD        dwRequestID;
  130.     char       szPhoneName[128]; // the phone's name 
  131. }PHONEINFO;
  132.  
  133. MYINFO myInfo;          //instance of MYINFO structure
  134. PHONEINFO myPhoneInfo[MAX_PHONE];  //instance of myPhoneInfo structure
  135.  
  136. LONG lRet;        //return code
  137. char buf[BUFSIZE];    // buffer for debug message
  138. char DataBuf[BUFSIZE]; //get/set data buffer;
  139.  
  140. DWORD i;
  141. DWORD dwHookSwitchDevs;
  142. DWORD dwLampMode;
  143. DWORD dwRingMode;
  144. DWORD dwRingVolume;
  145. DWORD dwHookSwitchVolume;
  146. DWORD dwPhoneStates;
  147. DWORD dwButtonModes;
  148. DWORD dwButtonStates;
  149. DWORD dwGain;
  150. HICON hIcon;
  151.  
  152. LONG lRet;
  153. char buf[BUFSIZE];
  154.  
  155. PHONECAPS*             pPhoneCaps;
  156. PHONEBUTTONINFO*  pButtonInfo;
  157. VARSTRING*            pVarString;
  158. PHONESTATUS*        pPhoneStatus;
  159. PHONEEXTENSIONID    ext_id;                                             
  160.  
  161.  
  162. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  163. {
  164.    switch( uMsg )
  165.    {
  166.       case WM_COMMAND :
  167.          switch( LOWORD( wParam ) )
  168.          {
  169.             case IDM_RUN :
  170.                   pPhoneStatus = (PHONESTATUS *) calloc (1, sizeof(PHONESTATUS)+1000);
  171.                     pPhoneStatus->dwTotalSize = sizeof(PHONESTATUS) + 1000;
  172.                     lRet = phoneGetStatus(myPhoneInfo[OWNER].hPhone, pPhoneStatus);
  173.                     if (lRet == 0)
  174.                    {
  175.                     wsprintf(buf, "phoneGetStatus succeeded!");
  176.                          SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  177.                          wsprintf( buf,"The Status Flags are: x%lx", pPhoneStatus->dwStatusFlags);
  178.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  179.                          wsprintf( buf,"The number of owners are: x%lx", pPhoneStatus->dwNumOwners);
  180.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  181.                          wsprintf( buf,"The number of apps with Monitor privilege is: x%lx", pPhoneStatus->dwNumMonitors);
  182.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  183.                          wsprintf( buf,"The current ring mode is: x%lx", pPhoneStatus->dwRingMode);
  184.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  185.                          wsprintf( buf,"The current ring volume is: x%lx", pPhoneStatus->dwRingVolume);
  186.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  187.                          wsprintf( buf,"The current Handset HookSwitch Mode is: x%lx", pPhoneStatus->dwHandsetHookSwitchMode);
  188.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  189.                          wsprintf( buf,"The current Handset volume is: x%lx", pPhoneStatus->dwHandsetVolume);
  190.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  191.                          wsprintf( buf,"The current Handset gain is: x%lx", pPhoneStatus->dwHandsetGain);
  192.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  193.                          wsprintf( buf,"The current Speaker HookSwitch Mode is: x%lx", pPhoneStatus->dwSpeakerHookSwitchMode);
  194.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  195.                          wsprintf( buf,"The current Speaker volume is: x%lx", pPhoneStatus->dwSpeakerVolume);
  196.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  197.                          wsprintf( buf,"The current Speaker gain is: x%lx", pPhoneStatus->dwSpeakerGain);
  198.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  199.                          wsprintf( buf,"The current Headset HookSwitch Mode is: x%lx", pPhoneStatus->dwHeadsetHookSwitchMode);
  200.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  201.                          wsprintf( buf,"The current Headset volume is: x%lx", pPhoneStatus->dwHeadsetVolume);
  202.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  203.                          wsprintf( buf,"The current Headset gain is: x%lx", pPhoneStatus->dwHeadsetGain);
  204.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  205.                          strcpy(buf, ((LPSTR)(pPhoneStatus)+pPhoneStatus->dwDisplayOffset));
  206.                   strcat( buf, "  is the phone current display." );
  207.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  208.                   strcpy(buf, ((LPSTR)(pPhoneStatus)+pPhoneStatus->dwOwnerNameOffset));
  209.                   strcat( buf, " is the application owner of the phone." );
  210.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  211.                    }
  212.                    else 
  213.                    {
  214.                         wsprintf( buf,"phoneGetStatus failed, err=x%lx", lRet);
  215.                        phoneError(lRet);
  216.                    }    
  217.                 
  218.                     free (pPhoneStatus);
  219.                break;
  220.  
  221.             case IDM_EXIT :
  222.                for (i = 0; i < myInfo.dwNumDevices; i++)
  223.                     phoneClose(myPhoneInfo[i].hPhone);
  224.                 
  225.                    phoneShutdown(myInfo.phoneApp);
  226.                DestroyWindow( hWnd );
  227.                break;
  228.          
  229.             case IDM_ABOUT :
  230.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  231.                break;
  232.          }
  233.                 
  234.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  235.  
  236.       
  237.        case WM_CREATE :
  238.  
  239.           hdc = GetDC (hWnd) ;
  240.           GetTextMetrics (hdc, &tm) ;
  241.           ReleaseDC (hWnd, hdc) ;
  242.  
  243.           hListWnd = CreateWindowEx( 0, "listbox", 
  244.                         " ",    
  245.                         WS_CHILD | WS_VISIBLE,  
  246.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  247.                         tm.tmAveCharWidth * 16 +
  248.                                    GetSystemMetrics (SM_CXVSCROLL), 
  249.                         tm.tmHeight * 5,  
  250.                         hWnd,              
  251.                         NULL,              
  252.                         hInst,         
  253.                         NULL               
  254.                         );
  255.       
  256.              //phoneInitialize
  257.                //...............................................
  258.             lRet = phoneInitialize(&myInfo.phoneApp, hInst, phoneCallback, lpszAppName, &myInfo.dwNumDevices);
  259.             if (lRet == 0) 
  260.             {
  261.                 
  262.                wsprintf(buf, "phoneInitialize succeeded!");
  263.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  264.             }
  265.                
  266.                else 
  267.                {
  268.                    wsprintf( buf,"phoneInitialize failed, err=x%lx",lRet);
  269.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  270.                     phoneError(lRet);
  271.                     break;
  272.             }                    
  273.                
  274.             //phoneNegotiateAPIVersion
  275.                   //...............................................
  276.             lRet = phoneNegotiateAPIVersion(myInfo.phoneApp, 0, APILOWVERSION, APIHIVERSION, 
  277.                                                     &myInfo.dwAPIVersion, &ext_id);
  278.             if (lRet == 0)                        
  279.             {
  280.                wsprintf(buf, "phoneNegotiateAPIVersion succeeded!");
  281.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  282.             }
  283.                   else 
  284.                   {
  285.                    wsprintf(buf, "phoneNegotiateAPIVersion failed, err=x%lx", lRet);
  286.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  287.                     phoneError(lRet);
  288.                     phoneShutdown(myInfo.phoneApp);
  289.                break;
  290.              }
  291.  
  292.                //phoneNegotiateExtVersion
  293.                //...............................................
  294.             lRet = phoneNegotiateExtVersion(myInfo.phoneApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  295.                                                 EXTHIVERSION, &myInfo.dwExtVersion);
  296.             if (lRet == 0)                        
  297.             {
  298.                     wsprintf(buf, "phoneNegotiateExtVersion succeeded!");
  299.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  300.               }
  301.                   else 
  302.                {
  303.                     wsprintf(buf, "phoneNegotiateExtVersion failed, err=x%lx", lRet);
  304.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  305.                       phoneError(lRet);
  306.                }
  307.  
  308.             //phoneOpen
  309.                //................................................................
  310.                for (i = 0; i < myInfo.dwNumDevices; i++)
  311.                {
  312.                    if ( i == 0)
  313.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  314.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_OWNER);
  315.                    else
  316.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  317.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_MONITOR);
  318.                    
  319.                    if (lRet == 0)
  320.                    {
  321.                      wsprintf(buf, "phoneOpen succeeded!");
  322.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  323.                   pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  324.                       pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  325.                          
  326.                       phoneGetDevCaps(myInfo.phoneApp,i,
  327.                       myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  328.                       strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwProviderInfoOffset));
  329.                   strcat( buf, " is the phone providor's name." );
  330.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  331.                   strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwPhoneNameOffset));
  332.                      
  333.                   if (i == 0)
  334.                   {
  335.                      strcat( buf, " is the phone's name opened with OWNER privilege." );
  336.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  337.                   }
  338.                   else
  339.                   {
  340.                      strcat( buf, " is the phone's name opened with MONITOR privilege." );
  341.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  342.                   }
  343.                }
  344.                    else 
  345.                    {
  346.                        wsprintf( buf,"phoneOpen failed, err=x%lx", lRet);
  347.                        phoneError(lRet);
  348.                       break;
  349.                }
  350.                   } 
  351.  
  352.             break;
  353.       
  354.       case WM_SIZE:
  355.           MoveWindow(hListWnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  356.          break;
  357.  
  358.       case WM_DESTROY :
  359.          PostQuitMessage(0);
  360.          break;
  361.             
  362.       default :
  363.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  364.    }
  365.  
  366.    return( 0L );
  367. }
  368.  
  369.  
  370.  
  371.  
  372. /****************************************************************************
  373.     FUNCTION: phoneCallback
  374.     PURPOSE:  callback function handles phone events
  375. ****************************************************************************/
  376. LRESULT CALLBACK phoneCallback (DWORD  dwDevice, DWORD dwMsg,
  377.                                 DWORD dwCallbackInst, DWORD dwParam1,
  378.                                 DWORD dwParam2,DWORD dwParam3)
  379. {
  380.     
  381.     switch (dwMsg)
  382.     {
  383.         case PHONE_REPLY:
  384.             if (dwParam1 == myPhoneInfo[OWNER].dwRequestID) 
  385.                    if (dwParam2 != 0)
  386.                 {
  387.                        wsprintf( buf,"Function failed, err=x%lx", lRet);
  388.                        phoneError(lRet);
  389.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  390.                    }
  391.             break;       
  392.  
  393.         case PHONE_STATE:
  394.         
  395.             if (dwParam1 == PHONESTATE_RINGMODE)
  396.             {
  397.                 lRet = phoneGetRing(myPhoneInfo[OWNER].hPhone, &dwRingMode, &dwRingVolume);
  398.                 if (lRet == 0)
  399.                {
  400.                 wsprintf(buf, "phoneGetRing succeeded!");
  401.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  402.                if (dwRingMode == 0)
  403.                     {
  404.                         wsprintf(buf, "The phone device is currently not ringing.");
  405.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  406.                }
  407.                     else
  408.                     {
  409.                         wsprintf(buf, "The phone is ringing with a Ring Mode pattern of x%lx", dwRingMode);
  410.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  411.                    wsprintf(buf, "The phnes's Ring Volume is x%lx", dwRingVolume);
  412.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  413.                     }
  414.                }
  415.                  else 
  416.                {
  417.                     wsprintf( buf,"phoneGetRing failed, err=x%lx", lRet);
  418.                    phoneError(lRet);
  419.                }        
  420.               
  421.               break;
  422.               }
  423.             
  424.  
  425.             if (dwParam1 == PHONESTATE_SPEAKERHOOKSWITCH)
  426.             {   
  427.                 lRet = phoneGetHookSwitch(myPhoneInfo[OWNER].hPhone, &dwHookSwitchDevs);
  428.                 if (lRet == 0)
  429.                {
  430.                wsprintf(buf, "phoneGetHookSwitch succeeded!");
  431.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  432.                
  433.                if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_SPEAKER)
  434.                     {
  435.                         wsprintf(buf, "The phone's HookSwitch Speaker is offhook!");
  436.                        SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  437.                     }
  438.                     else
  439.                     {
  440.                    wsprintf(buf, "The phone's HookSwitch Speaker is onhook!");
  441.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  442.                     }
  443.  
  444.               }
  445.                  else 
  446.                {
  447.                       wsprintf( buf,"phoneGetHookSwitch failed, err=x%lx", lRet);
  448.                    phoneError(lRet);
  449.                }    
  450.             break;                
  451.             }
  452.  
  453.             if (dwParam1 == PHONESTATE_SPEAKERVOLUME)
  454.             {   
  455.                 lRet = phoneGetVolume(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwHookSwitchVolume);
  456.                if (lRet == 0)
  457.                {
  458.                 wsprintf(buf, "phoneGetVolume succeeded!");
  459.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  460.                wsprintf(buf, "The current volume for the Speaker Hookswitch is x%lx", dwHookSwitchVolume);
  461.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  462.                }
  463.                  else 
  464.                {
  465.                     wsprintf( buf,"phoneGetVolume failed, err=x%lx", lRet);
  466.                    phoneError(lRet);
  467.                }    
  468.             break;                
  469.             }
  470.  
  471.             if (dwParam1 == PHONESTATE_SPEAKERGAIN)
  472.             {   
  473.                 lRet = phoneGetGain(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwGain);
  474.                 if (lRet == 0)
  475.                {
  476.                   wsprintf(buf, "phoneGetGain succeeded!");
  477.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  478.                     wsprintf(buf, "The current Gain is x%lx", dwGain);
  479.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  480.                }
  481.                  else 
  482.                {
  483.                       wsprintf( buf,"phoneGetGain failed, err=x%lx", lRet);
  484.                     phoneError(lRet);
  485.                }
  486.             break;                
  487.             }
  488.             
  489.             if (dwParam1 == PHONESTATE_DISPLAY)
  490.             {   
  491.                 pVarString = (VARSTRING *) calloc (1, sizeof(VARSTRING)+1000);
  492.                 pVarString->dwTotalSize = sizeof(VARSTRING) + 1000;
  493.                 lRet = phoneGetDisplay(myPhoneInfo[OWNER].hPhone, pVarString);
  494.                 if (lRet == 0)
  495.                {
  496.                   wsprintf(buf, "phoneGetDisplay succeeded!");
  497.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  498.                strcpy(buf, lpszTitle);
  499.                //strcpy(buf, ((LPSTR)(pVarString)+pVarString->dwStringOffset));
  500.                strcat( buf, " is the current phone display." );
  501.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  502.                }
  503.                  else 
  504.                {
  505.                    wsprintf( buf,"phoneGetDisplay failed, err=x%lx", lRet);
  506.                   phoneError(lRet);
  507.                }    
  508.                     
  509.                 free (pVarString);
  510.                 break;
  511.               }
  512.    }
  513.    return (TRUE);
  514.  
  515.  
  516. /****************************************************************************
  517.     FUNCTION: phoneError
  518.     PURPOSE:  phone error messages
  519. ****************************************************************************/
  520. void phoneError (LONG lrc)
  521. {
  522.  switch (lrc) {
  523.     case PHONEERR_INVALAPPHANDLE:
  524.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  525.        break;
  526.     case PHONEERR_BADDEVICEID:
  527.        MessageBox (hWnd,"The specified phone device ID is out of range.", "", 
  528.                    MB_OK);
  529.        break;
  530.     case PHONEERR_INCOMPATIBLEAPIVERSION:
  531.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  532.        break;
  533.     
  534.     case PHONEERR_INVALBUTTONLAMPID:
  535.        MessageBox (hWnd, "Invalid Button Lamp ID.", "", MB_OK);
  536.        break;
  537.  
  538.     case PHONEERR_INVALBUTTONMODE:
  539.        MessageBox (hWnd, "Invalid Button Mode.", "", MB_OK);
  540.        break;
  541.  
  542.     case PHONEERR_INVALBUTTONSTATE:
  543.        MessageBox (hWnd, "Invalid Button State", "", MB_OK);
  544.        break;
  545.  
  546.     case PHONEERR_INUSE:
  547.        MessageBox (hWnd, "Phone in Use.", "", MB_OK);
  548.        break;
  549.     
  550.     case PHONEERR_INVALHOOKSWITCHDEV:
  551.        MessageBox (hWnd, "Invalid Hookswitch Device.", "", MB_OK);
  552.        break;
  553.  
  554.     case PHONEERR_INVALHOOKSWITCHMODE:
  555.        MessageBox (hWnd, "Invalid Hookswitch Device Mode.", "", MB_OK);
  556.        break;
  557.  
  558.     case PHONEERR_INVALLAMPMODE:
  559.        MessageBox (hWnd, "Invalid Lamp Mode.", "", MB_OK);
  560.        break;
  561.      
  562.     case PHONEERR_INCOMPATIBLEEXTVERSION:
  563.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  564.        break;
  565.     case PHONEERR_NOMEM:
  566.        MessageBox (hWnd, "No memory","", MB_OK);
  567.        break;
  568.     case PHONEERR_NODRIVER:
  569.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  570.        break;
  571.     case PHONEERR_RESOURCEUNAVAIL:
  572.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  573.        break;
  574.     case PHONEERR_ALLOCATED:
  575.        MessageBox (hWnd, "Allocation error", "", MB_OK);
  576.        break;
  577.     case PHONEERR_INVALDATAID:
  578.        MessageBox (hWnd, "The data ID is out of range.", "", MB_OK);
  579.        break;
  580.     case PHONEERR_INVALDEVICECLASS:
  581.        MessageBox (hWnd, "The device class was invalid.", "", MB_OK);
  582.        break;
  583.     case PHONEERR_INVALPOINTER:
  584.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  585.                    "", MB_OK);
  586.        break;
  587.     case PHONEERR_OPERATIONFAILED:
  588.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  589.        break;
  590.     case PHONEERR_INVALPHONEHANDLE:
  591.        MessageBox (hWnd, "Invalid phone handle", "", MB_OK);
  592.        break;
  593.     case PHONEERR_INVALPHONESTATE :
  594.        MessageBox (hWnd, "Invalid call state for this function.", "", MB_OK);
  595.        break;
  596.     case PHONEERR_INVALPRIVILEGE:
  597.        MessageBox (hWnd, "Invalid privilege for this function.", "", MB_OK);
  598.        break;
  599.     case PHONEERR_NODEVICE:
  600.        MessageBox (hWnd, "No associated device for given class",
  601.                    "", MB_OK);
  602.        break;
  603.     case PHONEERR_OPERATIONUNAVAIL:
  604.        MessageBox (hWnd, "The operation is unavailable",
  605.                    "", MB_OK);
  606.        break;
  607.     case PHONEERR_INVALPARAM:
  608.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  609.        break; 
  610.  
  611.     case PHONEERR_INVALRINGMODE:
  612.             MessageBox(hWnd, "Invalid Ring Mode", "", MB_OK);
  613.        break; 
  614.  
  615.     }
  616.     
  617.              
  618. }
  619.  
  620. LRESULT CALLBACK About( HWND hDlg,           
  621.                         UINT message,        
  622.                         WPARAM wParam,       
  623.                         LPARAM lParam)
  624. {
  625.    switch (message) 
  626.    {
  627.        case WM_INITDIALOG: 
  628.                return (TRUE);
  629.  
  630.        case WM_COMMAND:                              
  631.                if (   LOWORD(wParam) == IDOK         
  632.                    || LOWORD(wParam) == IDCANCEL)    
  633.                {
  634.                        EndDialog(hDlg, TRUE);        
  635.                        return (TRUE);
  636.                }
  637.                break;
  638.    }
  639.  
  640.    return (FALSE); 
  641. }
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.